package bs.app.android;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;

public class HttpClient {
	public static final int CONNECTION_TIME_OUT = 30 * 1000;
	
	HttpURLConnection conn;

	public InputStream getInputStream(String url) throws IOException, SocketTimeoutException
	{	
		URL aURL = new URL(url);
//		Utils.initTimer("Open Connection");
//			Log.e("getInputStream", "conn = (HttpURLConnection) aURL.openConnection();");
		conn = (HttpURLConnection) aURL.openConnection();
//			Log.e("getInputStream", "DONE !!! conn = (HttpURLConnection) aURL.openConnection();");
//		Utils.endTimer("Open Connection");

		conn.setConnectTimeout(CONNECTION_TIME_OUT);

//		Utils.initTimer("connected time");
//			Log.e("getInputStream", "conn.connect();");
		conn.connect();
//			Log.e("getInputStream", "DONE !!! conn.connect();");
//		Utils.endTimer("connected time");

//		Utils.initTimer("Load time");
//			Log.e("getInputStream", "InputStream is = conn.getInputStream();");
		InputStream is = conn.getInputStream();
//			Log.e("getInputStream", "DONE !!! InputStream is = conn.getInputStream();");
//		Utils.endTimer("Load time");
		
		return is;
	}

	public void close()
	{
		disconnect();
		conn = null;
	}

	public void disconnect()
	{
		if(conn != null)
			conn.disconnect();
	}
}
